<link rel="stylesheet" type="text/css" href="<?= $base_url ?>css/faculty/search.css">

<div class="faculty">
	<div class="search">
		<div class="container-fluid">
			<div class="row-fluid">
				<legend><h1>Search Faculty</h1></legend>
                <div class="width100per">
                    <div class="width30per float-left">
                        <!--<form class="form-search"> -->
                        <?php echo form_open('faculty/search', array('class' => 'form-search')) ?>
                            <div class="search-filter-group">
                                <p>
                                    <input type="checkbox" name="cb_name_filter" value="name_filter" <?php if($cb_name) echo 'checked';?>>  Search by Name<br/>
                                    <input type="text" id="name_filter" name="name_filter" value="<?php echo $name?>"/>
                                </p>
                                <p>
                                    <input type="checkbox"  id="cb_dept_filter" name="cb_dept_filter" value="dept_filter" <?php if($cb_dept) echo 'checked';?>>  Search by Department<br/>
                                    <!--<input type="text" id="dept_filter" name="dept_filter" value="<?php echo $dept?>"/>-->
                                    <select id="dept_filter" name="dept_filter">
                                        <?php
                                        foreach($departments as $department)
                                        {
                                            $selected = "";
                                            if($dept == $department["Description"])
                                                $selected = "selected";
                                            echo '<option '.$selected.'>'.$department["Description"].'</option>';
                                        }

                                        ?>
                                    </select>
                                </p>
                                <p>
                                    <input type="checkbox" name="cb_spec_filter" value="spec_filter"  <?php if($cb_spec) echo 'checked'; ?>> Search by Specialization<br/>
                                    <input type="text" id="spec_filter" name="spec_filter" value="<?php echo $spec?>"/>
                                </p>

                                <p>
                                <br/>
                                    <h4>Archive/Unarchived Search Filter</h4>
                                    <input type="radio" name="rad_arch_filter" value="unarchive" <?php if($archive_search == 'unarchive') echo 'checked'; ?>/> Show Unarchived Only<br/>
                                    <input type="radio" name="rad_arch_filter" value="archive" <?php if($archive_search == 'archive') echo 'checked'; ?>/> Show Archived Only<br/>
                                    <input type="radio" name="rad_arch_filter" value="both" <?php if($archive_search == 'both' ) echo 'checked'; ?>/> Show Both<br/>
                                </p>
                            </div>
                            <button class="btn btn-primary" type="submit">Search</button>
                        <? echo form_close()?>
                        <!--</form>-->
                    </div>
                    <div class="width70per float-left">
                        <div class = 'search-results'>

                            <!--<div id="profile1" class="search-result">
                                <div class="image-holder">
                                    <img alt="140x140" src="<?php echo $base_url?>img/members/1.jpg" />
                                </div>
                                <div class="content-holder">
                                    <div class="details">
                                        <p class="firstname">First Name: Richard</p>
                                        <p class="middlename">Middle Name: Barnagas</p>
                                        <p class="lastname">Last Name: Domingmondomniog</p>
                                        <p class="degree">Degree: heh</p>
                                        <p class="specialization">Specialization: asdfadf</p>
                                    </div>
                                    <div class="clear-both"></div>
                                    <div class="control-holder">
                                        <a class="btn btn-primary" href="#">Go to Profile</a>
                                        <a class="btn" href="#">Archive</a>
                                        <a class="btn" href="#">Edit permissions</a>
                                        <a class="btn" href="#">Edit plantilla</a>
                                    </div>
                                </div>
                            </div> -->

                               <?php foreach($profiles as $profile)
                                {
                                    //<p class="department">Department: ' .$profile['profileFirstName']. '</p>
                                    echo
                                        '<div id="'.$profile['profileID'].'" class="search-result">
                                            <div class="image-holder">';

                                    $file = $base_url."img/members/".$profile['profileID'].".jpg";
                                    $file_headers = @get_headers($file);
                                    if($file_headers[0] == 'HTTP/1.1 404 Not Found') {
                                        echo '<img alt="140x140" src="'.$base_url.'img/members/blank.png"/>';
                                    }
                                    else {
                                        echo '<img alt="140x140" src="'.$base_url.'img/members/'.$profile['profileID'].'.jpg"/>';
                                    }


                                    echo
                                            '</div>
                                            <div class="content-holder">
                                                <div class="details">
                                                    <p class="firstname">First Name: '.$profile['profileFirstName'].'</p>
                                                    <p class="middlename">Middle Name: '.$profile['profileMiddleName'].'</p>
                                                    <p class="lastname">Last Name: '.$profile['profileLastName'].'</p>
                                                    <p class="specialization">Specialization: '.$profile['profileSpecialty'].'</p>
                                                    <p class="department">Department: '.$profile['profileDept'].'</p>
                                                </div>
                                                <div class="clear-both"></div>
                                                <div class="control-holder">
                                                    <a class="btn btn-primary" href="viewprofile/'. $profile['profileID']. '">Go to Profile</a>';

                                                    if($profile['profileStatus'] == 'Active')
                                                    {
                                                        echo '<div class="btn btnArchive btn-edit-status" href="'.$base_url.'faculty/editstatus/2">Archive Profile</div>';
                                                    }
                                                    else
                                                    {
                                                        echo '<div class="btn btnArchive btn-edit-status" href="'.$base_url.'faculty/editstatus/1">Un-archive Profile</div>';
                                                    }
                                                    echo
                                                    '<a class="btn btn_editPermission" href="#">Edit permissions</a>
                                                    <a class="btn" href="#">Edit plantilla</a>
                                                </div>
                                            </div>
                                        </div>';
                                }
                               ?>
                        </div>
                    </div>
                </div>
			</div>
		</div>
	</div>
</div>

<div id="edit-permission-form" title="Edit Permission"></div>
<div id="archive-member" title="Edit Permission"></div>


<script type="text/javascript">
    jQuery.noConflict();

    $("#cb_dept_filter").change( function(){
        if($(this).is(':checked'))
        {
            $("#dept_filter").prop("disabled", false);
        }
        else
        {
            $("#dept_filter").prop("disabled", true);
        }
    });

    $('div.btnArchive').on('click', function (event){
        clicked = this;
        searchResults = $('.search-result .btnArchive');

        for(int = 0; int < searchResults.size(); int++)
        {
            btn = searchResults[int];
            if(clicked == btn)
                break;
        }
        id = $($('.search-result')[int]).attr('id');

        $.ajax({
            url: '<?php echo $base_url; ?>faculty/editArchiveStatus/' + id,
            success: function(data){
                $( "#archive-member" ).html(data);
                $( "#archive-member" ).dialog( "open" );
            }
        });

    });

    $('.btn_editPermission').on("click", function( event ) {
        clicked = this;
        searchResults = $('.search-result .btn_editPermission');

        for(int = 0; int < searchResults.size(); int++)
        {
            btn = searchResults[int];
            if(clicked == btn)
                break;
        }
        id = $($('.search-result')[int]).attr('id');

        $.ajax({
            url: '<?php echo $base_url; ?>permission/edit/' + id,
            success: function(data){
                $("#edit-permission-form").html(data);
                $( "#edit-permission-form" ).dialog( "open" );
            }
        });
    });

    $( "#archive-member" ).dialog({
        autoOpen: false,
        height: 200,
        width: 350,
        modal: true,
        buttons: {
            Yes: function(){
                $('#change_status').submit();
            },
            No: function() {
                $( this ).dialog( "close" );
            }
        },
        close: function()
        {
        }
    });



    $( "#edit-permission-form" ).dialog({
        autoOpen: false,
        height: 340,
        width: 350,
        modal: true,
        buttons: {
            Save: function(){
                $('#edit_permission').submit();
            },
            Cancel: function() {
                $( this ).dialog( "close" );
            }
        },
        close: function()
        {
        }
    });

    $(function(){
        if($('#cb_dept_filter').is(':checked'))
        {
            $("#dept_filter").prop("disabled", false);
        }
        else
        {
            $("#dept_filter").prop("disabled", true);
        }
    });
</script>